<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
  <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    
    <title>less &mdash; GOZERWAVE v0.1 BETA documentation</title>
    <link rel="stylesheet" href="../_static/default.css" type="text/css" />
    <link rel="stylesheet" href="../_static/pygments.css" type="text/css" />
    <script type="text/javascript">
      var DOCUMENTATION_OPTIONS = {
        URL_ROOT:    '../',
        VERSION:     '0.1 BETA',
        COLLAPSE_MODINDEX: false,
        FILE_SUFFIX: '.html',
        HAS_SOURCE:  true
      };
    </script>
    <script type="text/javascript" src="../_static/jquery.js"></script>
    <script type="text/javascript" src="../_static/doctools.js"></script>
    <link rel="top" title="GOZERWAVE v0.1 BETA documentation" href="../index.html" />
    <link rel="next" title="plugins" href="plugins.html" />
    <link rel="prev" title="examples" href="examples.html" /> 
  </head>
  <body>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             accesskey="I">index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             accesskey="M">modules</a> |</li>
        <li class="right" >
          <a href="plugins.html" title="plugins"
             accesskey="N">next</a> |</li>
        <li class="right" >
          <a href="examples.html" title="examples"
             accesskey="P">previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>  

    <div class="document">
      <div class="documentwrapper">
        <div class="bodywrapper">
          <div class="body">
            
  <div class="section" id="less">
<h1>less<a class="headerlink" href="#less" title="Permalink to this headline">¶</a></h1>
<div class="section" id="module-gozerlib.less">
<h2>description<a class="headerlink" href="#module-gozerlib.less" title="Permalink to this headline">¶</a></h2>
<p>maintain bot output cache.</p>
<dl class="class">
<dt id="gozerlib.less.Less">
<em class="property">class </em><tt class="descclassname">gozerlib.less.</tt><tt class="descname">Less</tt><big>(</big><em>nr</em><big>)</big><a class="headerlink" href="#gozerlib.less.Less" title="Permalink to this definition">¶</a></dt>
<dd><p>Bases: <a title="(in Python v2.7)" class="reference external" href="http://docs.python.org/dev/library/functions.html#object"><tt class="xref docutils literal"><span class="pre">object</span></tt></a></p>
<p>output cache .. caches upto &lt;nr&gt; item of txt lines per nick.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>nr</em> (integer) &#8211; size of backlog</td>
</tr>
</tbody>
</table>
<dl class="method">
<dt id="gozerlib.less.Less.add">
<tt class="descname">add</tt><big>(</big><em>nick</em>, <em>listoftxt</em><big>)</big><a class="headerlink" href="#gozerlib.less.Less.add" title="Permalink to this definition">¶</a></dt>
<dd><p>add listoftxt to nick&#8217;s output .. set index for used by more 
commands.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first last simple">
<li><em>nick</em> (string) &#8211; nick to add txt to cache for</li>
<li><em>listoftxt</em> (list) &#8211; list of txt to cache</li>
</ul>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.less.Less.get">
<tt class="descname">get</tt><big>(</big><em>nick</em>, <em>index1</em>, <em>index2</em><big>)</big><a class="headerlink" href="#gozerlib.less.Less.get" title="Permalink to this definition">¶</a></dt>
<dd><p>return less entry.</p>
<p>entry is self.data[nick][index1][index2]</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>nick</em> (string) &#8211; nick to get data for</li>
<li><em>index1</em> (integer) &#8211; number of txtlines back</li>
<li><em>index2</em> (integer) &#8211; index into the txtlines</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">string</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.less.Less.more">
<tt class="descname">more</tt><big>(</big><em>nick</em>, <em>index1</em><big>)</big><a class="headerlink" href="#gozerlib.less.Less.more" title="Permalink to this definition">¶</a></dt>
<dd><p>return more entry pointed to by index .. increase index.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameters:</th><td class="field-body"><ul class="first simple">
<li><em>nick</em> (string) &#8211; nick to fetch data for</li>
<li><em>index1</em> (integer) &#8211; index into cache data</li>
</ul>
</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body"><p class="first last">tuple .. (txt, index)</p>
</td>
</tr>
</tbody>
</table>
</dd></dl>

<dl class="method">
<dt id="gozerlib.less.Less.size">
<tt class="descname">size</tt><big>(</big><em>nick</em><big>)</big><a class="headerlink" href="#gozerlib.less.Less.size" title="Permalink to this definition">¶</a></dt>
<dd><p>return sizes of cached output.</p>
<table class="docutils field-list" frame="void" rules="none">
<col class="field-name" />
<col class="field-body" />
<tbody valign="top">
<tr class="field"><th class="field-name">Parameter:</th><td class="field-body"><em>nick</em> (string) &#8211; nick to get cache sizes for</td>
</tr>
<tr class="field"><th class="field-name">Return type:</th><td class="field-body">list .. list of sizes</td>
</tr>
</tbody>
</table>
</dd></dl>

</dd></dl>

</div>
<div class="section" id="code">
<h2>code<a class="headerlink" href="#code" title="Permalink to this headline">¶</a></h2>
<div class="highlight-python"><table class="highlighttable"><tr><td class="linenos"><pre>  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124</pre></td><td class="code"><div class="highlight"><pre><span class="c"># gozerlib/less.py</span>
<span class="c">#</span>
<span class="c">#</span>

<span class="sd">&quot;&quot;&quot; maintain bot output cache. &quot;&quot;&quot;</span>

<span class="c"># gozerlib imports</span>

<span class="kn">from</span> <span class="nn">utils.limlist</span> <span class="kn">import</span> <span class="n">Limlist</span>

<span class="k">class</span> <span class="nc">Less</span><span class="p">(</span><span class="nb">object</span><span class="p">):</span>

    <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">        output cache .. caches upto &lt;nr&gt; item of txt lines per nick.</span>

<span class="sd">        :param nr: size of backlog</span>
<span class="sd">        :type nr: integer</span>

<span class="sd">    &quot;&quot;&quot;</span>

    <span class="k">def</span> <span class="nf">__init__</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nr</span><span class="p">):</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">index</span> <span class="o">=</span> <span class="p">{}</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">nr</span> <span class="o">=</span> <span class="n">nr</span>

    <span class="k">def</span> <span class="nf">add</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nick</span><span class="p">,</span> <span class="n">listoftxt</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">            add listoftxt to nick&#39;s output .. set index for used by more </span>
<span class="sd">            commands.</span>

<span class="sd">            :param nick: nick to add txt to cache for</span>
<span class="sd">            :type nick: string</span>
<span class="sd">            :param listoftxt: list of txt to cache</span>
<span class="sd">            :type listoftxt: list</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">nick</span> <span class="o">=</span> <span class="n">nick</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

        <span class="c"># see if we already have cached output .. if not create limited list</span>
        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">nick</span><span class="p">):</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">]</span> <span class="o">=</span> <span class="n">Limlist</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">nr</span><span class="p">)</span>

        <span class="c"># add data</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">]</span><span class="o">.</span><span class="n">insert</span><span class="p">(</span><span class="mf">0</span><span class="p">,</span> <span class="n">listoftxt</span><span class="p">)</span>
        <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">nick</span><span class="p">]</span> <span class="o">=</span> <span class="mf">1</span>

    <span class="k">def</span> <span class="nf">get</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nick</span><span class="p">,</span> <span class="n">index1</span><span class="p">,</span> <span class="n">index2</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">             return less entry.</span>

<span class="sd">             entry is self.data[nick][index1][index2]</span>

<span class="sd">             :param nick: nick to get data for</span>
<span class="sd">             :type nick: string</span>
<span class="sd">             :param index1: number of txtlines back</span>
<span class="sd">             :type index1: integer</span>
<span class="sd">             :param index2: index into the txtlines </span>
<span class="sd">             :type index2: integer</span>
<span class="sd">             :rtype: string</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">nick</span> <span class="o">=</span> <span class="n">nick</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">][</span><span class="n">index1</span><span class="p">][</span><span class="n">index2</span><span class="p">]</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="bp">None</span>
        <span class="k">return</span> <span class="n">txt</span>

    <span class="k">def</span> <span class="nf">more</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nick</span><span class="p">,</span> <span class="n">index1</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">             return more entry pointed to by index .. increase index.</span>

<span class="sd">             :param nick: nick to fetch data for</span>
<span class="sd">             :type nick: string</span>
<span class="sd">             :param index1: index into cache data</span>
<span class="sd">             :type index1: integer</span>
<span class="sd">             :rtype: tuple .. (txt, index)</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">nick</span> <span class="o">=</span> <span class="n">nick</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">nr</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">nick</span><span class="p">]</span>
        <span class="k">except</span> <span class="ne">KeyError</span><span class="p">:</span>
            <span class="n">nr</span> <span class="o">=</span> <span class="mf">1</span>

        <span class="k">try</span><span class="p">:</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">][</span><span class="n">index1</span><span class="p">][</span><span class="n">nr</span><span class="p">]</span>
            <span class="n">size</span> <span class="o">=</span> <span class="nb">len</span><span class="p">(</span><span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">][</span><span class="n">index1</span><span class="p">])</span><span class="o">-</span><span class="n">nr</span>
            <span class="bp">self</span><span class="o">.</span><span class="n">index</span><span class="p">[</span><span class="n">nick</span><span class="p">]</span> <span class="o">=</span> <span class="n">nr</span><span class="o">+</span><span class="mf">1</span>
        <span class="k">except</span> <span class="p">(</span><span class="ne">KeyError</span><span class="p">,</span> <span class="ne">IndexError</span><span class="p">):</span>
            <span class="n">txt</span> <span class="o">=</span> <span class="bp">None</span>
            <span class="n">size</span> <span class="o">=</span> <span class="mf">0</span>

        <span class="k">return</span> <span class="p">(</span><span class="n">txt</span><span class="p">,</span> <span class="n">size</span><span class="o">-</span><span class="mf">1</span><span class="p">)</span>

    <span class="k">def</span> <span class="nf">size</span><span class="p">(</span><span class="bp">self</span><span class="p">,</span> <span class="n">nick</span><span class="p">):</span>

        <span class="sd">&quot;&quot;&quot;</span>
<span class="sd">             return sizes of cached output.</span>

<span class="sd">             :param nick: nick to get cache sizes for</span>
<span class="sd">             :type nick: string</span>
<span class="sd">             :rtype: list .. list of sizes</span>

<span class="sd">        &quot;&quot;&quot;</span>

        <span class="n">nick</span> <span class="o">=</span> <span class="n">nick</span><span class="o">.</span><span class="n">lower</span><span class="p">()</span>
        <span class="n">sizes</span> <span class="o">=</span> <span class="p">[]</span>

        <span class="k">if</span> <span class="ow">not</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="o">.</span><span class="n">has_key</span><span class="p">(</span><span class="n">nick</span><span class="p">):</span>
            <span class="k">return</span> <span class="n">sizes</span>

        <span class="k">for</span> <span class="n">i</span> <span class="ow">in</span> <span class="bp">self</span><span class="o">.</span><span class="n">data</span><span class="p">[</span><span class="n">nick</span><span class="p">]:</span>
            <span class="n">sizes</span><span class="o">.</span><span class="n">append</span><span class="p">(</span><span class="nb">len</span><span class="p">(</span><span class="n">i</span><span class="p">))</span>

        <span class="k">return</span> <span class="n">sizes</span>
</pre></div>
</td></tr></table></div>
</div>
</div>


          </div>
        </div>
      </div>
      <div class="sphinxsidebar">
        <div class="sphinxsidebarwrapper">
            <h3><a href="../index.html">Table Of Contents</a></h3>
            <ul>
<li><a class="reference external" href="">less</a><ul>
<li><a class="reference external" href="#module-gozerlib.less">description</a></li>
<li><a class="reference external" href="#code">code</a></li>
</ul>
</li>
</ul>

            <h4>Previous topic</h4>
            <p class="topless"><a href="examples.html"
                                  title="previous chapter">examples</a></p>
            <h4>Next topic</h4>
            <p class="topless"><a href="plugins.html"
                                  title="next chapter">plugins</a></p>
            <h3>This Page</h3>
            <ul class="this-page-menu">
              <li><a href="../_sources/gozerlib/less.txt"
                     rel="nofollow">Show Source</a></li>
            </ul>
          <div id="searchbox" style="display: none">
            <h3>Quick search</h3>
              <form class="search" action="../search.html" method="get">
                <input type="text" name="q" size="18" />
                <input type="submit" value="Go" />
                <input type="hidden" name="check_keywords" value="yes" />
                <input type="hidden" name="area" value="default" />
              </form>
              <p class="searchtip" style="font-size: 90%">
              Enter search terms or a module, class or function name.
              </p>
          </div>
          <script type="text/javascript">$('#searchbox').show(0);</script>
        </div>
      </div>
      <div class="clearer"></div>
    </div>
    <div class="related">
      <h3>Navigation</h3>
      <ul>
        <li class="right" style="margin-right: 10px">
          <a href="../genindex.html" title="General Index"
             >index</a></li>
        <li class="right" >
          <a href="../modindex.html" title="Global Module Index"
             >modules</a> |</li>
        <li class="right" >
          <a href="plugins.html" title="plugins"
             >next</a> |</li>
        <li class="right" >
          <a href="examples.html" title="examples"
             >previous</a> |</li>
        <li><a href="../index.html">GOZERWAVE v0.1 BETA documentation</a> &raquo;</li> 
      </ul>
    </div>
    <div class="footer">
      &copy; Copyright 2009, Bart Thate.
      Last updated on Nov 14, 2009.
      Created using <a href="http://sphinx.pocoo.org/">Sphinx</a> 0.6.3.
    </div>
  </body>
</html>